﻿using Koala.Pro.CodeGenerator.UI.DatabaseModel.Schema;
using Koala.Pro.CodeGenerator.UI.Models;

namespace Koala.Pro.CodeGenerator.UI.Common.Adapter
{
    public class CreateTableAdapter : AbstractAdapter
    {
        private ICollection<ColumnInfo> columnList;

        private string tableName = string.Empty;

        public CreateTableAdapter(string tableName, ICollection<ColumnInfo> columnList, string templateFile)
            : base(templateFile)
        {
            DirectoryOfOutput = "StoreProcedures";
            FileExtension = ".sql";
            this.tableName = tableName;
            this.columnList = columnList;
        }

        public override List<FileNameAndCode> ExecuteString()
        {
            List<FileNameAndCode> list = new List<FileNameAndCode>();
            FileNameAndCode fileNameAndCode = new FileNameAndCode();
            PrepareHeader();
            FileNameOfOutput = tableName;
            fileNameAndCode.FileName = FileNameOfOutput + FileExtension;
            fileNameAndCode.Code = OutputString();
            list.Add(fileNameAndCode);
            return list;
        }

        private void PrepareHeader()
        {
            context.Put("TableName", tableName);
            context.Put("ColumnList", columnList);
        }
    }
}
